package com.coocaa.ops.admin.v1.upload.properties;

import com.alibaba.nacos.api.config.annotation.NacosConfigurationProperties;
import com.coocaa.ops.admin.base.language.CommonLanguageProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

/**
 * @author tangminghong
 * @date 2020-06-18
 */
@Component
@NacosConfigurationProperties(dataId = "admin-upload.yml", groupId = "${nacos.config.group}", autoRefreshed = true)
@Getter
@Setter
public class UploadProperties implements InitializingBean {
    private static CommonLanguageProperties commonLanguageProperties;

    /**
     * 图片主机
     */
    private String imgHost;
    /**
     * apk主机
     */
    private String apkHost;

    /**
     * 临时上传目录-本地测试需要修改自己本地地址
     */
    private String tempUploadDir;
    /**
     * 环境目录
     */
    private String envDir;
    /**
     * 是否上传ftp
     */
    private Boolean enableUploadFtp = true;
    /**
     * apk解析程序 aapt.exe 存放目录
     */
    private String apkAaptDir;
    /**
     * 图片类型限制
     */
    private String imgTypeLimit;
    /**
     * 视频类型限制
     */
    private String videoTypeLimit;

    @Override
    public void afterPropertiesSet() throws Exception {
        Assert.hasText(imgHost, "ftp-img host " + commonLanguageProperties.getNotNull());
        Assert.hasText(apkHost, "ftp-apk host " + commonLanguageProperties.getNotNull());
        Assert.hasText(tempUploadDir, "ftp uploads temporary directories " + commonLanguageProperties.getNotNull());
        Assert.hasText(envDir, "ftp upload environment directory " + commonLanguageProperties.getNotNull());
        Assert.hasText(apkAaptDir, "aapt.exe program directory configuration " + commonLanguageProperties.getNotNull());
        Constants.IMG_HOST = imgHost;
        Constants.APK_HOST = apkHost;
        Constants.TEMP_UPLOAD_DIR = tempUploadDir;
        Constants.ENV_DIR = envDir;
        Constants.ENABLE_UPLOAD_FTP = enableUploadFtp;
        Constants.APK_AAPT_DIR = apkAaptDir;
        Constants.IMG_TYPE_LIMIT = imgTypeLimit;
    }

    @Autowired
    public void setCommonLanguageProperties(CommonLanguageProperties commonLanguageProperties) {
        UploadProperties.commonLanguageProperties = commonLanguageProperties;
    }

    public static final class Constants {
        public static String IMG_HOST;
        public static String APK_HOST;
        public static String ART_HOST;
        public static String TEMP_UPLOAD_DIR;
        public static String ENV_DIR;
        public static boolean ENABLE_UPLOAD_FTP;
        public static String APK_AAPT_DIR;
        public static String IMG_TYPE_LIMIT;
    }
}
